<?php


// get parameters that were posted

	$success = 0;

	$options = array(	//'metadata_name_value_pairs'	=>	array('product_type_id' => $product_type_id),
						'types'				=>	"object",
						'subtypes'			=>	"county",						
						'limit'				=>	32,
						
					);
	$county_lists = elgg_get_entities_from_metadata($options);
	
	$counter = count($county_lists);
	
	
	if ($counter < 2){
		
	$county = new ElggObject();
	
	$county->title = "Carlow";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	
	$county = new ElggObject();

	$county->title = "Cavan";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();
	
	$county->title = "Clare";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	$county = new ElggObject();

	$county->title = "Cork";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();

	$county->title = "Derry";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	$county = new ElggObject();
	
	$county->title = "Donegal";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();		
	
	$county = new ElggObject();
	
	$county->title = "Down";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();		
	
	$county = new ElggObject();
	
	$county->title = "Dublin";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	$county = new ElggObject();

	$county->title = "Fermanagh";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	

	$county = new ElggObject();
	
	$county->title = "Galway";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	

	$county = new ElggObject();
	
		$county->title = "Kerry";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	$county = new ElggObject();
	
		$county->title = "Kildare";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
		$county->title = "Kilkenny";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
		$county->title = "Laois";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
		$county->title = "Leitrim";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
		$county->title = "Limerick";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
		$county->title = "Longford";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	$county = new ElggObject();
	
		$county->title = "Louth";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();	
	
	
	$county = new ElggObject();
	
			$county->title = "Mayo";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();
	
			$county->title = "Meath";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();
	
			$county->title = "Monaghan";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	
	$county = new ElggObject();
			$county->title = "Offaly";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	
	$county = new ElggObject();
			$county->title = "Roscommon";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();
			$county->title = "Sligo";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();
	
	$county = new ElggObject();
	
			$county->title = "Tipperary";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();

	$county = new ElggObject();
			$county->title = "Tyrone";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();

	$county = new ElggObject();
			$county->title = "Waterford";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();

	$county = new ElggObject();
			$county->title = "Westmeath";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();

	$county = new ElggObject();
			$county->title = "Wexford";
	$county->subtype="county";
	$county->access_id = 0;
	$county->save();

	$county = new ElggObject();
			$county->title = "Wicklow";
	$county->subtype="county";
	$county->access_id = 0;
		if($county->save()){
		$error = 0;
		}
		else{
			$error = 1;
		}	
		
	}
	
	
// do something


// now see if it worked
if ($error==1) {
	register_error(elgg_echo('import failed'));
	forward($CONFIG->url."mod/import_towns/pages/index.php");
}

if($counter==0){
	system_message(elgg_echo('Counties imported'));
	forward($CONFIG->url."mod/import_towns/pages/index.php");
}
else{
	system_message(elgg_echo('Counties already imported'));
	forward($CONFIG->url."mod/import_towns/pages/index.php");
}

// we had success so forward the user somewhere and display success message

